classdef PXA < PSA
    
          
    methods
         function this = PXA(GPIB_controller, GPIB_address, address)
            this = this@PSA(GPIB_controller, GPIB_address, address);
            fopen(this.conn);
            fprintf(this.conn,'*RST');
         end
         
         function delete(this)
            fclose(this.conn);
            delete(this.conn);
         end
        
         function setStartFreq(this)
            
             cmd = sprintf(':FREQ:STAR %fGHz',this.startFreq);
             fprintf(this.conn,cmd);
         end
         
         function setStopFreq(this)
             
             cmd = sprintf(':FREQ:STOP %fGHz',this.stopFreq);
             fprintf(this.conn,cmd);
         end
         
         function setCenterFreq(this)
             
             cmd = sprintf(':FREQ:CENT %fGHz',this.centerFreq);
             fprintf(this.conn,cmd);
         end
         
         function setSpan(this)
             
             cmd = sprintf(':FREQ:SPAN %fMHz',this.span);
             fprintf(this.conn,cmd);
         end
         
         function setRBW(this)
             
             cmd = sprintf(':BWID %f',this.rbw);
             fprintf(this.conn,cmd);
         end
         
         function result = getTraceData(this)
             
             fprintf(this.conn,':FORM:DATA REAL,32');
             fprintf(this.conn,':FORM:BORD SWAP');
             fprintf(this.conn,':INIT:IMM');
             opc = query(this.conn,'*OPC?');
             
             fprintf(this.conn,':TRAC? TRACE1'); %CALC:DATA?
             %result = fscanf(this.conn);
             %result = str2double(query(this.conn,'TRAC? TRACE1'));
             result = binblockread(this.conn,'float');
             fread(this.conn,1);
            
             
         end
         
         function setSweepPoints(this)
             
             cmd = sprintf(':SWE:POIN %f',this.sweepPoints);
             fprintf(this.conn,cmd);
         end
         
         function [num freq amp] = getPeaks(this, threshold, excursion) 
             %cmd = sprintf(':CALC:MARK:PEAK:THR %f',threshold); 
             %fprintf(this.conn,cmd);
             %cmd = sprintf(':CALC:MARK:PEAK:EXC %f',threshold); 
             %fprintf(this.conn,cmd);
             cmd = sprintf(':CALC:DATA1:PEAK? %d, %d, AMPL, ALL', threshold, excursion); 
             fprintf(this.conn,cmd);
             %peaks = str2num(query(this.conn,':TRAC:MATH:PEAK?'));  
             %freq = peaks(1:2:end-1)';
             %amp = peaks(2:2:end)';
              peak_data = binblockread(this.conn,'float32');
              
              num = peak_data(1);
              amp = peak_data(2:2:end);
              freq = peak_data(3:2:end);

         end
         
          
             
             
         
    end
end